package com.luoye.lj.wstool.wsdm;

import com.luoye.lj.wstool.common.StringUtils;
import com.luoye.lj.wstool.generator.ICodeGenerator;
import com.luoye.lj.wstool.wsdm.entity.WsdtEntity;
import com.luoye.lj.wstool.wsdm.entity.WsdtField;
import com.luoye.lj.wstool.wsdm.entity.WsdtFieldDesc;

/*
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 2016/7/7
 * Time: 15:45
 * To change this template use File | Settings | File Templates.
 */
public class HtmlStatisticTargetCodeGenerator implements ICodeGenerator {
    private WsdtEntity wsdtEntity;

    public HtmlStatisticTargetCodeGenerator(WsdtEntity wsdtEntity) {
        this.wsdtEntity = wsdtEntity;
    }

    @Override
    public String codeGenerate() {
        String code="";
        int i=0;
        if(this.wsdtEntity!=null){
            if(this.wsdtEntity.getFieldList()!=null){
                for(WsdtField wsdtField:this.wsdtEntity.getFieldList()){
                    if(wsdtField.getWsdtFieldDesc()==null) {
                        if (i % 4 == 0) {
                            code += "            <div class=\"row screen-group\">\n";
                        }
                        code += "" +
                                "                <div class=\"col-lg-3 col-md-3 col-sm-3 col-xs-12 form-group\">\n" +
                                "                        <label>" + wsdtField.getDescription() + "总计：</label>\n" +
                                "                        <label id=\"" + wsdtField.getFieldName() + "_statistic\"></label>\n" +
                                "                </div>\n";
                        if (i % 4 == 3) {
                            code += "            </div>\n";
                        }
                        i++;
                    }else{
                        if(wsdtField.getWsdtFieldDesc().isStatistic()){
                            if (i % 4 == 0) {
                                code += "            <div class=\"row screen-group\">\n";
                            }
                            code += "" +
                                    "                <div class=\"col-lg-3 col-md-3 col-sm-3 col-xs-12 form-group\">\n" +
                                    "                        <label>" + wsdtField.getWsdtFieldDesc().getText() + "总计：</label>\n";
                            code += "                        <label id=\"" + wsdtField.getFieldName() + "_statistic\"></label>\n";
                            code += "                </div>\n";
                            if (i % 4 == 3) {
                                code += "            </div>\n";
                            }
                            i++;
                        }
                    }
                }
            }
        }
        if(i%4!=0){
            code+="            </div>\n";
        }
        return code;
    }
}
